import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DlgRetirar extends javax.swing.JDialog {
	private static final long serialVersionUID = 6152331662790110865L;
	
	private JSeparator jSeparator1;
	private JButton btnSalir;
	private JButton btnCancelar;
	private JButton btnInscribir;
	private JTextField txtNombre;
	private JTextField txtCedula;
	private JLabel lblCedula;
	private JLabel lblNombre;
	private JLabel lblApellido;
	private JTextField txtApellido;
	
	private Seccion seccion;
	private DlgRetirar dlgr;
	/**
	* Auto-generated main method to display this JDialog
	*/
	/*public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				DlgRetirar inst = new DlgRetirar(frame);
				inst.setVisible(true);
			}
		});
	}*/
	
	public DlgRetirar(JFrame frame, Seccion secc) {
		super(frame);
		dlgr = this;
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		seccion = secc;
		initGUI();
	}
	
	private void initGUI() {
		this.setModal(true);
		try {
			{
				getContentPane().setLayout(null);
				this.setTitle("Retirar Estudiante");
				{
					jSeparator1 = new JSeparator();
					getContentPane().add(jSeparator1);
					jSeparator1.setBounds(2, 153, 389, 40);
				}
				{
					btnSalir = new JButton();
					getContentPane().add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(254, 176, 84, 21);
					btnSalir.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							dlgr.dispose();
						}
					});
				}
				{
					btnCancelar = new JButton();
					getContentPane().add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(128, 176, 88, 21);
					btnCancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							Reestablecer();
						}
					});
				}
				{
					btnInscribir = new JButton();
					getContentPane().add(btnInscribir);
					btnInscribir.setText("Retirar");
					btnInscribir.setBounds(24, 178, 81, 20);
					btnInscribir.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							if(ValidarCampo())
							{
								String ced = txtCedula.getText();
								Estudiante es;
								if ((es=seccion.buscarEstudiante(ced)) != null){
									
									txtCedula.setText(es.getCedula());
									txtNombre.setText(es.getNombre());
									txtApellido.setText(es.getApellido());
									//txtCedula.setEditable(false);
									int resp=JOptionPane.showConfirmDialog(null, "Esta seguro de retirar este estudiante", "Confirmar Retiro ", JOptionPane.YES_NO_OPTION);
									if(resp==JOptionPane.YES_OPTION)
									{
										seccion.retirarEstudiante(ced);
									    JOptionPane.showMessageDialog(null, "Estudiante Retirado","Informacion",JOptionPane.INFORMATION_MESSAGE);
									    
									}
									
									
								}
								else
								{
									JOptionPane.showMessageDialog(null, "El Estudiante no esta inscrito","Informacion",JOptionPane.INFORMATION_MESSAGE);
								}
								Reestablecer();
							}
						}
					});
				}
				{
					txtApellido = new JTextField();
					getContentPane().add(txtApellido);
					txtApellido.setText("");
					txtApellido.setBounds(79, 103, 158, 21);
					txtApellido.setEnabled(true);
					txtApellido.setEditable(false);
				}
				{
					lblApellido = new JLabel();
					getContentPane().add(lblApellido);
					lblApellido.setText("Apellido:");
					lblApellido.setBounds(24, 100, 41, 14);
				}
				{
					txtNombre = new JTextField();
					getContentPane().add(txtNombre);
					txtNombre.setText("");
					txtNombre.setBounds(79, 62, 158, 21);
					txtNombre.setEditable(false);
				}
				{
					lblNombre = new JLabel();
					getContentPane().add(lblNombre);
					lblNombre.setText("Nombre:");
					lblNombre.setBounds(24, 59, 41, 14);
				}
				{
					lblCedula = new JLabel();
					getContentPane().add(lblCedula);
					lblCedula.setText("Cedula:");
					lblCedula.setBounds(24, 18, 39, 13);
				}
				{
					txtCedula = new JTextField();
					getContentPane().add(txtCedula);
					txtCedula.setBounds(81, 14, 88, 20);
				}
			}
			this.setSize(375, 255);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public boolean ValidarCampo()
	{
		if(txtCedula.getText().equals(""))
		{
		   JOptionPane.showMessageDialog(null, "Ingrese una cedula","Campo Vacio",JOptionPane.INFORMATION_MESSAGE);
		   return false;
		}	
				else return true;
	}
	public void Reestablecer(){
		txtCedula.setText("");
		txtNombre.setText("");
		txtApellido.setText("");
		
	}
}
